package com.echoesnet.echoesshortvideo.ViewModels;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;

import com.echoesnet.echoesshortvideo.Api.Subscriber.SilenceSubscriber;
import com.echoesnet.echoesshortvideo.Beans.UserBean;
import com.echoesnet.echoesshortvideo.Repositories.UserDetailRepository;

/**
 * Copyright (C) 2018 科技发展有限公司
 * 完全享有此软件的著作权，违者必究
 * 负责驱动UI
 *
 * @author ben
 * @version 1.0
 * @modifier
 * @createDate 2018/4/19 18:05
 * @description
 */
public class UserDetailViewModel extends ViewModel
{
    private MutableLiveData<UserBean> userDetail = new MutableLiveData<>();
    private MutableLiveData<String> updateUser = new MutableLiveData<>();
    private UserDetailRepository uDetailRepository;

    public LiveData<UserBean> getUserDetail()
    {
        return userDetail;
    }
    public LiveData<String> updateUserDetail()
    {
        return updateUser;
    }


    public UserDetailViewModel()
    {
        this.uDetailRepository = new UserDetailRepository();
    }

    /**
     * 查询用户信息
     *
     * @param uid 用户id
     */
    public void requestUserDetail(String uid)
    {
        uDetailRepository.getUser(uid, new SilenceSubscriber<UserBean>()
        {
            @Override
            public void onNext(UserBean user)
            {
                super.onNext(user);
                userDetail.setValue(user);
            }
        });
    }

    /**
     * 修改用户信息
     */
    public void updateUserInfo(UserBean bean)
    {
        uDetailRepository.updateUserInfo(bean,new SilenceSubscriber<String>()
        {
            @Override
            public void onNext(String response)
            {
                super.onNext(response);
                updateUser.setValue(response);
            }
        });
    }
}
